<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>添加人员信息</title>
    <!-- Bootstrap -->
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="container">
    <form class="form-inline" action="/person_add_after" method="post" onsubmit="return check()" autocomplete="off">
        <nav th:replace="~{system/sys/sys_topbar::top}"></nav>
        <div class="container" style="padding-top: 20px">
            <div class="row form-group" style="padding-left: 20rem">
                <label for="personAccount" style="padding-right: 30px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    账号
                </label>
                <input type="text" name="personAccount" class="form-control" id="personAccount" placeholder="请输入账号" style="width: 50rem"><label id="accountUsed" style="color: #ff0000"></label>
                <!--<span class="label label-warning">账号不可修改</span>-->
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="password" style="padding-right: 30px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    密码
                </label>
                <input type="password" name="password" class="form-control" id="password" placeholder="请输入密码" style="width: 50rem" required>
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="password1" style="padding-right: 30px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    确认密码
                </label>
                <input type="password" name="password1" class="form-control" id="password1" placeholder="请再次输入密码" style="width: 50rem" required>
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label style="padding-right: 30px; display:inline;font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    状态
                </label>
                <select style="width: 50rem; height: 34px; border-radius: 4px; border: 1px solid #b6bec5" name="status">
                    <option value="在职" >在职</option>
                    <option value="休假" >休假</option>
                    <option value="在职" >离退</option>
                </select>
                <!--<input th:value="${personInfo.status}" type="text" name="status" class="form-control" id="status" placeholder="请输入状态" style="width: 50rem">-->
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="personName" style="padding-right: 30px; display:inline;font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    姓名
                </label>
                <input type="text" name="personName" class="form-control" id="personName" placeholder="请输入姓名" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label style="padding-right: 30px; display:inline;font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    性别
                </label>
                <select style="width: 50rem; height: 34px; border-radius: 4px; border: 1px solid #b6bec5" name="sex">
                    <option value=0 >男</option>
                    <option value=1 >女</option>
                </select>
                <!--<input th:if="${personInfo.sex eq 0}" th:value="男" type="text" name="sex" class="form-control" id="sexMan" placeholder="请输入性别" style="width: 50rem">-->
                <!--<input th:if="${personInfo.sex eq 1}" th:value="女" type="text" name="sex" class="form-control" id="sexFemale" placeholder="请输入性别" style="width: 50rem">-->
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="phoneNumber" style="padding-right: 30px; display:inline;font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    手机
                </label>
                <input type="text" name="phoneNumber" class="form-control" id="phoneNumber" placeholder="请输入手机" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="address" style="padding-right: 30px; display:inline;font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    住址
                </label>
                <input type="text" name="address" class="form-control" id="address" placeholder="请输入住址" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="belongedCompany" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    所属单位
                </label>
                <input type="text" name="belongedCompany" class="form-control" id="belongedCompany" placeholder="平台/所属公司名" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="idCard" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    身份证号
                </label>
                <input type="text" name="idCard" class="form-control" id="idCard" placeholder="请输入身份证号" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="bankNumber" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    银行账号
                </label>
                <input type="text" name="bankNumber" class="form-control" id="bankNumber" placeholder="请输入银行账号" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="born" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    出生日期
                </label>
                <input type="text" name="born" class="form-control" id="born" placeholder="请输入出生日期" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="education" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    文化程度
                </label>
                <input type="text" name="education" class="form-control" id="education" placeholder="请输入文化程度" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    政治面貌
                </label>
                <select style="width: 50rem; height: 34px; border-radius: 4px; border: 1px solid #b6bec5" name="political">
                    <option value="中共党员" >中共党员</option>
                    <option value="中共预备党员" >中共预备党员</option>
                    <option value="共青团员" >共青团员</option>
                    <option value="民革党员" >民革党员</option>
                    <option value="民盟盟员" >民盟盟员</option>
                    <option value="民建会员" >民建会员</option>
                    <option value="民进会员" >民进会员</option>
                    <option value="农工党党员" >农工党党员</option>
                    <option value="致公党党员" >致公党党员</option>
                    <option value="九三学社社员" >九三学社社员</option>
                    <option value="台盟盟员" >台盟盟员</option>
                    <option value="无党派人士" >无党派人士</option>
                    <option value="群众" >群众</option>
                </select>
                <!--<input th:value="${personInfo.political}" type="text" name="political" class="form-control" id="political" placeholder="请输入政治面貌" style="width: 50rem">-->
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="property" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    职工性质
                </label>
                <input type="text" name="property" class="form-control" id="property" placeholder="管理员" style="width: 50rem" th:value="管理员" readonly>
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    用工性质
                </label>
                <select style="width: 50rem; height: 34px; border-radius: 4px; border: 1px solid #b6bec5" name="character">
                    <option value="正式工" >正式工</option>
                    <option value="临时工" >临时工</option>
                    <option value="实习生" >实习生</option>
                </select>
                <!--<input th:value="${personInfo.character}" type="text" name="character" class="form-control" id="character" placeholder="请输入用工性质" style="width: 50rem">-->
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
            <div class="row form-group" style="padding-left: 20rem">
                <label for="workDate" style="padding-right: 18px; font-weight: bold; font-family: 'Hiragino Sans GB', 'Microsoft Yahei UI', 'Microsoft Yahei', 微软雅黑, 'Segoe UI', Tahoma, 宋体b8b体, SimSun, sans-serif;">
                    入职时间
                </label>
                <input type="text" name="workDate" class="form-control" id="workDate" placeholder="请输入入职时间" style="width: 50rem">
            </div>
            <div class="row" style=" padding-top: 20px;padding-bottom: 20px"><hr style="background-color: aliceblue; height: 2px; margin: unset; border: unset"></div>
        </div>
        <div class="container">
            <div class="row text-center">
                <button id="addButton" type="submit" class="btn btn-primary" style="margin-right: 50px; width: 90px; margin-bottom: 40px">确认添加</button>
                <a th:href="@{/person_manage}"><button type="button" class="btn btn-primary" style="margin-right: 50px; width: 90px; margin-bottom: 40px">返回</button></a>
            </div>
        </div>

    </form>
</div>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="../jquery-3.3.1.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<script>
    var flag = 0;

    $(function () {
        $("#personAccount").change(function () {
            $("#accountUsed").html("");
            flag = 0;
            personAccountUsed();
        })
    })

    function personAccountUsed() {
        var personAccount = $("#personAccount").val();

        $.ajax({
            url: "/findAllPerson",
            success: function (data) {
                $.each(data.data, function (i, item) {
                    if (personAccount == null)
                        $("#accountUsed").html("");
                    if (personAccount === (item.personAccount)){
                        $("#accountUsed").html("账号已存在!");
                        flag = 1;
                    }
                })
            }
        })
    }

    function check() {
        var personAccount = $("#personAccount").val();
        var personName = $("#personName").val();
        var phoneNumber = $("#phoneNumber").val();
        var property = $("#property").val();
        var password = $("#password").val();
        var password1 = $("#password1").val();
        if (personAccount == null || personAccount === '' ){
            alert("账号不能为空!");
            return false;
        }
        else if (flag === 1){
            alert("账号已存在!");
            return false;
        }
        else if (password1 !== password){
            alert("两次密码不一致!");
            if (event.preventDefault) {
                event.preventDefault();
            } else {
                event.returnValue = false;
            }
        }
        else if (personName == null || personName === ''){
            alert("姓名不能为空!")
            return false;
        }
        else if (phoneNumber == null || phoneNumber === ''){
            alert("电话不能为空!");
            return false;
        }
        else if (property == null || property === ''){
            alert("职工性质不能为空!");
            return false;
        }
        return true;
    }

</script>

</body>
</html>